using System;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace UsrControls
{
    public class LabelTemplate : ITemplate
    {
        string _colName = String.Empty;
        string _id = String.Empty;
        string _cssClass = String.Empty;

        public LabelTemplate(string id, string columnName, string cssClass)
        {
            _colName = columnName;
            _id = id;
            _cssClass = cssClass;
        }

        public LabelTemplate(string id, string columnName)
        {
            _colName = columnName;
            _id = id;
        }


        //<asp:Label CssClass="textBold" id="lblColumnTotalDay_0" runat="server" />

        public void InstantiateIn(Control container)
        {
            Anthem.Label lbl = new Anthem.Label();
            lbl.ID = _id;
            if (_cssClass != String.Empty)
            {
                lbl.Attributes.Add("class", _cssClass);
            }
            if (_colName != null)
            {
                lbl.DataBinding += new EventHandler(this.OnDataBinding);
            }
            container.Controls.Add(lbl);
        }

        public void OnDataBinding(object sender, EventArgs e)
        {
            Anthem.Label lbl = (Anthem.Label)sender;
            DataGridItem container = (DataGridItem)lbl.NamingContainer;
            lbl.Text = ((DataRowView)container.DataItem)[_colName].ToString();
        }
    }
}
